package com.zxx.casserver.modules.user.service.impl;

import com.baomidou.mybatisplus.core.conditions.query.QueryWrapper;
import com.baomidou.mybatisplus.extension.service.impl.ServiceImpl;

import com.zxx.casserver.modules.user.entity.UserAccountDO;
import com.zxx.casserver.modules.user.mapper.UserAccountMapper;
import com.zxx.casserver.modules.user.service.IUserAccountService;
import org.springframework.stereotype.Service;
import org.springframework.util.ObjectUtils;

import java.util.HashSet;
import java.util.List;
import java.util.Set;

/**
 * <p>
 * 用户账户登陆表 服务实现类
 * </p>
 *
 * @author zhoukai
 * @since 2022-07-15
 */
@Service
public class UserAccountServiceImpl extends ServiceImpl<UserAccountMapper, UserAccountDO> implements IUserAccountService {

    @Override
    public boolean saveUserAccount(UserAccountDO userAccountDO) {
        userAccountDO.setCreateTime(System.currentTimeMillis());
        userAccountDO.setUpdateTime(System.currentTimeMillis());
        return save(userAccountDO);
    }

    @Override
    public Set<Long> getUidByAccount(String account) {
        QueryWrapper<UserAccountDO> queryWrapper = new QueryWrapper<>();
        queryWrapper.like("account", account);
        List<UserAccountDO> accountList = list(queryWrapper);
        if (ObjectUtils.isEmpty(accountList)) {
            return null;
        }
        Set<Long> uidSet = new HashSet<>();
        for (UserAccountDO userAccountDO : accountList) {
            uidSet.add(userAccountDO.getUid());
        }
        return uidSet;
    }
}
